package person.aoao.library.service.impl;

import person.aoao.library.entity.TimeList;
import person.aoao.library.dao.TimeListDao;
import person.aoao.library.service.TimeListService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (TimeList)表服务实现类
 *
 * @author makejava
 * @since 2023-05-05 10:15:40
 */
@Service("timeListService")
public class TimeListServiceImpl implements TimeListService {
    @Resource
    private TimeListDao timeListDao;

    /**
     * 通过ID查询单条数据
     *
     * @param timeid 主键
     * @return 实例对象
     */
    @Override
    public TimeList queryById(Integer timeid) {
        return this.timeListDao.queryById(timeid);
    }

    /**
     * 分页查询
     *
     * @param timeList    筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<TimeList> queryByPage(TimeList timeList, PageRequest pageRequest) {
        long total = this.timeListDao.count(timeList);
        return new PageImpl<>(this.timeListDao.queryAllByLimit(timeList, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param timeList 实例对象
     * @return 实例对象
     */
    @Override
    public TimeList insert(TimeList timeList) {
        this.timeListDao.insert(timeList);
        return timeList;
    }

    /**
     * 修改数据
     *
     * @param timeList 实例对象
     * @return 实例对象
     */
    @Override
    public TimeList update(TimeList timeList) {
        this.timeListDao.update(timeList);
        return this.queryById(timeList.getTimeid());
    }

    /**
     * 通过主键删除数据
     *
     * @param timeid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer timeid) {
        return this.timeListDao.deleteById(timeid) > 0;
    }
}
